import os
import pandas as pd

def merge_csv_files(directory_path, output_file):
    # 获取目录下的所有CSV文件
    csv_files = [f for f in os.listdir(directory_path) if f.endswith('.csv')]
    
    # 用于存储数据的列表
    data_frames = []

    for file in csv_files:
        # 读取CSV文件
        file_path = os.path.join(directory_path, file)
        df = pd.read_csv(file_path)
        data_frames.append(df)

    # 合并所有数据框
    combined_df = pd.concat(data_frames, ignore_index=True)

    # 将合并后的数据框保存到输出文件
    combined_df.to_csv(output_file, index=False)

# 示例使用
directory_path = 'F:\\Personal\\data\\行情数据\\15min\\2024'
output_file = 'F:\\Personal\\data\\行情数据\\15min\\2024\\15min_2024.csv'

merge_csv_files(directory_path, output_file)
